package com.yf1706.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yf1706.bean.ComprehensiveQuestion;
import com.yf1706.bean.GapFilling;
import com.yf1706.bean.Multiselect;
import com.yf1706.bean.QuestionBank;
import com.yf1706.dao.jpa.fillingJDAO;
import com.yf1706.dao.jpa.questionBankJDAO;
import com.yf1706.dao.mybatis.GapFillingMDAO;

@Service
public class fillingService {
	
	@Autowired
	private fillingJDAO fjdao;
	@Autowired
	private GapFillingMDAO gfmdao;
	@Autowired
	private questionBankJDAO qbjdao;
	
	public List<GapFilling> findByQuestionBank(QuestionBank q){
		return fjdao.findByQuestionBank(q);
	}
	
	public List<GapFilling> querybyQbId(int qbId){
		return gfmdao.querybyQbId(qbId);
	}
	
	//在题库添加题目
			public void questionbankAddFilling(String answer,String examQuestion,String qbId,String createPeople){
				GapFilling sc=new GapFilling();
				sc.setAnswer(answer);
				sc.setCreateDate(new Date());
				sc.setCreatePeople(createPeople);
				sc.setExamQuestion(examQuestion);
				int qbid=Integer.parseInt(qbId);
				sc.setQuestionBank(qbjdao.findByQbId(qbid));
				fjdao.save(sc);
			}

			public void deleteQuestionBankFilling(int gapFillingId) {
				fjdao.deleteById(gapFillingId);
				
			}

			public List<GapFilling> findByGapFillingId(int fillingId) {
				// TODO Auto-generated method stub
				return fjdao.findByGapFillingId(fillingId);
			}

			public List<GapFilling> queryAllFilling() {
				// TODO Auto-generated method stub
				return gfmdao.queryAllFilling();
			}

			public List<GapFilling> queryAllByQbIdAndExamQuestion(int qbId, String examQuestion) {
				
				return gfmdao.queryAllByQbIdAndExamQuestion(qbId,examQuestion);
			}

			public void add(String examQuestion, String answer, int qbId, String sessionUserName) {
				GapFilling gap=new GapFilling();
				gap.setAnswer(answer);
				gap.setExamQuestion(examQuestion);
				gap.setCreateDate(new Date());
				gap.setCreatePeople(sessionUserName);
				gap.setQuestionBank(qbjdao.findByQbId(qbId));
				fjdao.save(gap);
				
			}


}
